package web.controller.employer;

import common.consts.Consts;
import common.consts.ContentType;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import service.RecruitmentService;
import service.ServiceResponse;
import web.Routes;
import web.controller.Base;
import web.security.Protection;

import static common.consts.Recruitments.Status;

/**
 * Created by tyler on 25/6/15.
 */
@RestController
@RequestMapping(Routes.Employer.RECRUITMENTS)
public class Recruitments extends Base {

    @Autowired
    private RecruitmentService recruitmentService;

    @Protection
    @RequestMapping(method = RequestMethod.GET, produces = ContentType.JSON)
    public ServiceResponse get(@RequestParam(value = "status", defaultValue = "") String status,
                               @RequestParam(value = "page", defaultValue = "1") int page) {
        if (StringUtils.isBlank(status)) {
            status = Status.NORMAL.name();
        }

        long employer = getUserIdFromAuthHeader();

        return recruitmentService.find4EmployerByStatus(employer, status, page, Consts.DEFAULT_ROWS);
    }

}
